package com.tranq;

import org.apache.hadoop.io.ArrayWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Writable;

/**
 *  以数组方式存储 统计值：
 *  0: 上行流量， 1：下行流量， 2： 总流量
 */
public class TrafficStatRecord extends ArrayWritable {

    public TrafficStatRecord(Integer up, Integer down, Integer total){
        super(IntWritable.class);
        Writable[] data = new IntWritable[]{
                new IntWritable(up),
                new IntWritable(down),
                new IntWritable(total)};
        set(data);
    }

    public TrafficStatRecord(){
        super(IntWritable.class);
    }

    public int get(int index){
        Writable[] tmp = get();
        if(index < tmp.length){
            return ((IntWritable)tmp[index]).get();
        }
        return 0;
    }

    @Override
    public String toString() {
        Writable[] data = get();
        return String.format("%s\t%s\t%s", data[0].toString(), data[1].toString(), data[2].toString());
    }
}
